USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0002_COMISION]    Script Date: 11/24/2011 14:30:59 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WASP_M0002_COMISION]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[WASP_M0002_COMISION]
GO

USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0002_COMISION]    Script Date: 11/24/2011 14:30:59 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[WASP_M0002_COMISION]
AS
BEGIN
	SELECT	a.ppsuc AS suc 
			,a.ppcta  AS cta 
			,a.ppoper AS oper
			,SUM(b.coimp) AS comision
	INTO	comisiones
	FROM	fsd601 AS a (NOLOCK)
      		,fsd026 AS b (NOLOCK) 
	WHERE	a.Pppap = b.copap
	AND		a.d601su+100 = b.Cocod 
	GROUP BY a.ppsuc
			,a.ppcta,
			a.ppoper
END

GO


